import babelpolyfill from 'babel-polyfill'
// import './promise-polyfill'
import Vue from 'vue'
import App from './App'
import util from './common/util'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import {sync} from 'vuex-router-sync'
import Vuex from 'vuex'
import VueResource  from 'vue-resource'
import NProgress from 'nprogress'//页面顶部进度条
import 'nprogress/nprogress.css'
import Login from './pages/Login.vue'
import Home from './pages/Home.vue'

import Page11 from './pages/nav1/Page11.vue'
import Page111 from './pages/nav1/Page111.vue'
import Page12 from './pages/nav1/Page12.vue'
import Page13 from './pages/nav1/Page13.vue'
import Page21 from './pages/nav2/Page21.vue'
import Page211 from './pages/nav2/Page211.vue'
import Page212 from './pages/nav2/Page212.vue'
import Page22 from './pages/nav2/Page22.vue'
import Page31 from './pages/nav3/Page31.vue'
import Page311 from './pages/nav3/Page311.vue'
import Page312 from './pages/nav3/Page312.vue'
import Page313 from './pages/nav3/Page313.vue'
import Page314 from './pages/nav3/Page314.vue'
import Page315 from './pages/nav3/Page315.vue'
import Page3152 from './pages/nav3/Page3152.vue'
import Page317 from './pages/nav3/Page317.vue'
import Page318 from './pages/nav3/Page318.vue'
import Page319 from './pages/nav3/Page319.vue'
import Page3110 from './pages/nav3/Page3110.vue'
import Page32 from './pages/nav3/Page32.vue'
import Page33 from './pages/nav3/Page33.vue'
import Page331 from './pages/nav3/Page331.vue'
import Page332 from './pages/nav3/Page332.vue'
import Page333 from './pages/nav3/Page333.vue'
import Page334 from './pages/nav3/Page334.vue'
import Page335 from './pages/nav3/Page335.vue'
import Page336 from './pages/nav3/Page336.vue'
import Page3361 from './pages/nav3/Page3361.vue'
import Page3362 from './pages/nav3/Page3362.vue'
import Page337 from './pages/nav3/Page337.vue'
import Page338 from './pages/nav3/Page338.vue'
import Page339 from './pages/nav3/Page339.vue'
import Page3391 from './pages/nav3/Page3391.vue'
import Page41 from './pages/nav4/Page41.vue'
import Page42 from './pages/nav4/Page42.vue'
import Page51 from './pages/nav5/Page51.vue'
import Page52 from './pages/nav5/Page52.vue'
import Page61 from './pages/nav6/Page61.vue'
import Page62 from './pages/nav6/Page62.vue'
import Page63 from './pages/nav6/Page63.vue'
import Page64 from './pages/nav6/Page64.vue'
import Page65 from './pages/nav6/Page65.vue'
import Page71 from './pages/nav7/Page71.vue'
import Page81 from './pages/nav8/Page81.vue'

import Page91 from './pages/nav9/Page91.vue'
import Page92 from './pages/nav9/Page92.vue'
import Page93 from './pages/nav9/Page93.vue'
import Page94 from './pages/nav9/Page94.vue'
import Page95 from './pages/nav9/Page95.vue'
import Page96 from './pages/nav9/Page96.vue'
import Page97 from './pages/nav9/Page97.vue'

import Page101 from './pages/nav10/Page101.vue'
import Page102 from './pages/nav10/Page102.vue'
import Page103 from './pages/nav10/Page103.vue'
import Page104 from './pages/nav10/Page104.vue'
import Page105 from './pages/nav10/Page105.vue'
import Page106 from './pages/nav10/Page106.vue'

import Pagea1 from './pages/nava/Pagea1.vue'
import Pagea2 from './pages/nava/Pagea2.vue'
import Pagea3 from './pages/nava/Pagea3.vue'

import Pageb1 from './pages/navb/Pageb1.vue'
import Pageb2 from './pages/navb/Pageb2.vue'



import * as filters from './filters'

Vue.use(VueResource);
Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.use(Vuex);

Vue.http.interceptors.push((request, next) => {
  // request.headers["Content-Type"] = "application/json;";
  // 请求发送前的处理逻辑
  console.log(request);
  next((response) => {
    // 请求发送后的处理逻辑
    console.log(response);
    util.resInit(response);
    // 根据请求的状态，response参数会返回给successCallback或errorCallback
    return response
  })
});
Vue.http.interceptors.push((request, next) => {
  let timeout;
  // 如果某个请求设置了_timeout,那么超过该时间，会终端该（abort）请求,并执行请求设置的钩子函数onTimeout方法，不会执行then方法。
  // if (request._timeout) {
  if (false) {
    timeout = setTimeout(() => {
      if (request.onTimeout) {
        request.onTimeout(request);
        request.abort()
      }
    }, request._timeout);
  }
  next((response) => {
    clearTimeout(timeout);
    return response;
  })
});


// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

const routes = [
  {
    path: '/login',
    component: Login,
    hidden: true//不显示在导航中
  },
  //{ path: '/main', component: Main },
  {
    path: '/',
    component: Home,
    name: '',
    iconCls: 'fa fa-newspaper-o',//图标样式class
    leaf: true,
    resource_path: "/user/menu/login",
    children: [
      {path: '/page11', component: Page111, name: '信息总览', resource_path: "/user/menu/login"},
      {path: '/page12/:id', component: Page12, name: '租户信息'},
      {path: '/page13', component: Page13, name: '修改密码'},
    ]
  },
  /* {
    path: '/',
    component: Home,
    name: '环安大数据智能',
    iconCls: 'fa fa-id-card-o',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page91', component: Page91, name: '能源管理', resource_path: '/user/menu/monitor'},
      {path: '/page92', component: Page92, name: '动力管理', resource_path: '/user/menu/monitor'},
      {path: '/page93', component: Page93, name: '报警智能', resource_path: '/user/menu/monitor'},
      // {path: '/page94', component: Page94, name: '易化点检', resource_path: '/user/menu/monitor'},
      {path: '/page95', component: Page95, name: '环保监视', resource_path: '/user/menu/monitor'},
      {path: '/page96', component: Page96, name: '智能维保', resource_path: '/user/menu/monitor'},
      {path: '/page97', component: Page97, name: '生命安全', resource_path: '/user/menu/monitor'},
    ]
  }, */
  {
    path: '/',
    component: Home,
    name: '能源管理',
    // leaf: true,//只有一个节点
    iconCls: 'fa fa-bolt',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/Pagea1', component: Pagea1, name: '实时监控', resource_path: '/user/menu/monitor'},
      {path: '/Pagea2', component: Pagea2, name: '能耗分析', resource_path: '/user/menu/monitor'},
      {path: '/Pagea3', component: Pagea3, name: '能耗优化', resource_path: '/user/menu/monitor'},
    ]
  },
  {
    path: '/',
    component: Home,
    name: '动力管理',
    // leaf: true,//只有一个节点
    iconCls: 'fa fa-cubes',
    resource_path: '/user/menu/privilege',
    children: [
      // {path: '/page92', component: Page92, name: '动力管理', resource_path: '/user/menu/monitor'},
      {path: '/Pageb1', component: Pageb1, name: '动力与品质', resource_path: '/user/menu/monitor'},
      {path: '/Pageb2', component: Pageb2, name: '动力与成本', resource_path: '/user/menu/monitor'},
    ]
  },
  {
    path: '/',
    component: Home,
    name: '报警智能',
    leaf: true,//只有一个节点
    iconCls: 'fa fa-exclamation-triangle',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page93', component: Page93, name: '报警智能', resource_path: '/user/menu/monitor'},
      
    ]
  },
  {
    path: '/',
    component: Home,
    name: '智能维保',
    leaf: true,//只有一个节点
    iconCls: 'fa fa-binoculars',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page96', component: Page96, name: '智能维保', resource_path: '/user/menu/monitor'},
    ]
  },
  {
    path: '/',
    component: Home,
    name: '生命安全',
    leaf: true,//只有一个节点
    iconCls: 'fa fa-heartbeat',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page97', component: Page97, name: '生命安全', resource_path: '/user/menu/monitor'},
    ]
  },

  {
    path: '/',
    component: Home,
    name: '环保监视',
    iconCls: 'fa fa-tree',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page101', component: Page101, name: '环保监测', resource_path: '/user/menu/monitor'},
      {path: '/page102', component: Page102, name: '机台监测', resource_path: '/user/menu/monitor'},
      {path: '/page103', component: Page103, name: '危废跟踪', resource_path: '/user/menu/monitor'},
      // {path: '/page94', component: Page94, name: '易化点检', resource_path: '/user/menu/monitor'},
      {path: '/page104', component: Page104, name: '应急中心', resource_path: '/user/menu/monitor'},
      {path: '/page105', component: Page105, name: '动力与环保', resource_path: '/user/menu/monitor'},
      // {path: '/page106', component: Page106, name: '动力BOM成本', resource_path: '/user/menu/monitor'},
    ]
  },
  
  {
    path: '/',
    component: Home,
    name: '大数据基础平台',
    iconCls: 'fa fa-tasks',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page52', component: Page52, name: '平台监控', resource_path: '/user/menu/monitor'},
      {path: '/page41', component: Page41, name: '租户管理', resource_path: '/user/menu/renant'},
      {path: '/page31', component: Page31, name: '任务调度', resource_path: '/user/menu/task'},
      {path: '/page21', component: Page21, name: '权限管理', resource_path: '/user/menu/privilege/role'},
      {path: '/page61', component: Page61, name: '数据管理', resource_path: '/user/menu/dataMgmt/HDFS'},
      {path: '/page81', component: Page81, name: '系统操作审计', resource_path: '/user/menu/auditMgmt/log'},
      {path: '/page71', component: Page71, name: '数据质量稽核', isshow: true, resource_path: '/user/menu/audit'},
    ]
  },



  {
    path: '/',
    component: Home,
    name: '数据管理',
    hidden:true,
    iconCls: 'fa fa-database',
    resource_path: '/user/menu/dataMgmt',
    children: [
      {path: '/page61', component: Page61, name: 'HDFS', resource_path: '/user/menu/dataMgmt/HDFS'},
      {path: '/page62', component: Page62, name: 'HIVE', resource_path: '/user/menu/dataMgmt/HIVE'},
      {path: '/page63', component: Page63, name: 'HBASE', resource_path: '/user/menu/dataMgmt/HBASE'},
      {path: '/page64', component: Page64, name: 'HIVE SQL', hide: true},
      {path: '/page65', component: Page65, name: 'HIVE 历史', hide: true},
    ]
  },

  {
    path: '/',
    component: Home,
    name: '',
    iconCls: 'fa fa-cubes',
    leaf: true,//只有一个节点
    hidden:true,
    resource_path: '/user/menu/task',
    children: [
      // {path: '/page31', component: Page31, name: '任务管理', resource_path: '/user/menu/task'},
      {path: '/page32', component: Page32, name: '数据源管理'},
      {path: '/page311/:id', component: Page311, name: '任务信息'},
      {path: '/page312', component: Page312, name: 'Hive信息'},
      {path: '/page313/:id', component: Page313, name: 'Hive信息'},
      {path: '/page314/:id', component: Page314, name: 'Hive信息'},
      {path: '/page315', component: Page315, name: 'Coordinator'},
      {path: '/page3152', component: Page3152, name: 'Workflow'},
      {path: '/page316/:id', component: Page315, name: '失败数据'},
      {path: '/page317', component: Page317, name: 'All DAGs'},
      {path: '/page318', component: Page318, name: 'DAG'},
      {path: '/page319', component: Page319, name: '稽核详情'},
      {path: '/page3110', component: Page3110, name: '任务分组'},
      {path: '/page33', component: Page33, name: 'Yarn'},
      {path: '/page331/:id', component: Page331, name: 'Application'},
      {path: '/page332/:id', component: Page332, name: 'Attempt'},
      {path: '/page333', component: Page333, name: 'History'},
      {path: '/page334', component: Page334, name: 'Task'},
      {path: '/page335', component: Page335, name: 'Attempt'},
      {path: '/page336', component: Page336, name: 'Logs'},
      {path: '/page3361', component: Page3361, name: 'LogsList'},
      {path: '/page3362', component: Page3362, name: 'Logs'},
      {path: '/page337', component: Page337, name: 'Logs'},
      {path: '/page338', component: Page338, name: 'Active Jobs'},
      {path: '/page339', component: Page339, name: 'Task'},
      {path: '/page3391', component: Page3391, name: 'TaskID'},
    ]
  },
  /* {
    path: '/',
    component: Home,
    name: '',
    iconCls: 'fa fa-calendar-check-o',
    leaf: true,//只有一个节点
    resource_path: '/user/menu/audit',
    children: [
      {path: '/page71', component: Page71, name: '数据质量稽核', isshow: true, resource_path: '/user/menu/audit'},
    ]
  }, */
  /* {
    path: '/',
    component: Home,
    leaf: true,//只有一个节点
    name: '',
    iconCls: 'fa fa-pie-chart',
    resource_path: '/user/menu/monitor',
    children: [
      {path: '/page52', component: Page52, name: '平台监控', resource_path: '/user/menu/monitor'},
    ]
  }, */
  {
    path: '/',
    component: Home,
    name: '',
    iconCls: 'fa fa-users',
    leaf: true,//只有一个节点
    hidden:true,
    resource_path: '/user/menu/renant',
    children: [
      // {path: '/page41', component: Page41, name: '租户管理', resource_path: '/user/menu/renant'},
      {path: '/page42', component: Page42, name: '配置资源', hide: true}
    ]
  },
  {
    path: '/',
    component: Home,
    name: '权限管理',
    iconCls: 'fa fa-id-card-o',
    resource_path: '/user/menu/privilege',
    children: [
      {path: '/page21', component: Page21, name: '角色管理', resource_path: '/user/menu/privilege/role'},
      {path: '/page211', component: Page211, name: '功能权限', hide: true},
      {path: '/page212', component: Page212, name: '数据权限', hide: true},
      {path: '/page22', component: Page22, name: '用户管理', resource_path: '/user/menu/privilege/user'}
    ]
  },
  /* {
    path: '/',
    component: Home,
    name: '审计管理',
    iconCls: 'fa fa-bar-chart',
    resource_path: '/user/menu/auditMgmt',
    leaf: true,
    children: [
      {path: '/page81', component: Page81, name: '系统操作审计', resource_path: '/user/menu/auditMgmt/log'}
    ]
  }, */


 


];

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  NProgress.start();
  next()
})

router.afterEach(transition => {
  NProgress.done();
});

sync(store, router)

Vue.http.interceptors.push((request, next) => {
  next((res) => {
    if (res.status == '401' || (!res.body || res.body.retCode == '401'|| res.body.retCode == '402')) {
      util.restoreSystem();
      router.replace('/login');
    }
    return res
  })
});

new Vue({
  el: '#app',
  template: '<App/>',
  router,
  store,
  components: {App}
  //render: h => h(Login)
}).$mount('#app')

//router.replace('/login')
export default router

